package examples.rmi;

import java.rmi.*;

import java.io.*;

/**
 *
 * @author prabhat.totoo
 */
public class ConfusedClient {

    public static void main(String args[]) {

        BufferedReader reader;

        try {
            /* Create your BufferedReader just like the Sockets
             * example
             */
            reader = new BufferedReader(new InputStreamReader(System.in));

            /* Declare an object of the type of the Remote
             * Interface, and then connect to the remote rmiregistry
             * and ask it for the object that was put there.
             */
            ConfusedInterface confused = (ConfusedInterface) Naming.lookup("rmi://localhost:1099/confused");

            System.out.println("Found remote implementation of ConfusedInterface");

            String sLine = reader.readLine();
            String sResponse = null;

            while (!sLine.equalsIgnoreCase("exit")) {
                sResponse = confused.processString(sLine);
                System.out.println("Response: " + sResponse);
                sLine = reader.readLine();
            }

        } catch (Exception e) {
            
            /* There are quite a few exceptions thrown that we do
             * not want to handle individually.
             */
            System.out.println("An error occurred.");
        }
    }
}
